package com.ibeeking.found.log.rest.controller.v1;

import com.ibeeking.found.log.rest.service.ILogCodeService;
import com.ibeeking.found.log.service.common.param.LogCodeParam;
import com.ibeeking.found.log.service.common.query.LogCodePageQuery;
import com.ibeeking.found.log.service.common.query.LogCodeQuery;
import com.ibeeking.found.log.service.common.vo.LogCodeVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName LogCodeController控制器
 * @Description
 * @Author ibeeking
 * @Date 2021-02-25 16:42
 **/
@RestController
@RequestMapping("/b/logCode/v1")
public class LogCodeController {

    @Resource
    private ILogCodeService logCodeServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "日志编码列表")
    @PostMapping(value = "/list")
    public List<LogCodeVO> list(@RequestBody LogCodeQuery logCodeQuery) {
        return logCodeServiceImpl.list(logCodeQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "日志编码分页列表")
    @PostMapping(value = "/pageList")
    public Page<LogCodeVO> pageList(@RequestBody LogCodePageQuery logCodePageQuery) {
        return logCodeServiceImpl.pageList(logCodePageQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "日志编码添加")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) LogCodeParam logCodeParam) {
        return logCodeServiceImpl.add(logCodeParam);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "日志编码修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) LogCodeParam logCodeParam) {
        return logCodeServiceImpl.modify(logCodeParam);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "日志编码查询")
    @GetMapping(value = "/view/{id}")
    public LogCodeVO view(@PathVariable("id") Long id) {
        return logCodeServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "日志编码删除")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return logCodeServiceImpl.del(id);
    }
}